import { Login } from "@/api/interface/index";

/**
 * @name 登录模块
 */
// * 用户登录接口
export const loginApi = (params: Login.ReqLoginForm) => {
	// 本地mock数据，用于测试
	return new Promise<Login.ResLogin>((resolve, reject) => {
		setTimeout(() => {
			// 模拟登录验证
			if ((params.username === "admin" || params.username === "user") && params.password) {
				resolve({
					access_token: "mock_token_" + Date.now()
				});
			} else {
				reject({
					response: {
						data: {
							msg: "用户名或密码错误"
						}
					}
				});
			}
		}, 1000); // 模拟网络延迟
	});
};

// * 获取按钮权限
export const getAuthorButtons = () => {
	// 本地 mock：返回空的按钮权限，避免 404 提示
	return Promise.resolve<{ code: number; msg: string; data: Login.ResAuthButtons }>({
		code: 200,
		msg: "success",
		data: {}
	});
};

// * 获取菜单列表
export const getMenuList = () => {
	// 基于路由模块生成菜单
	const mockMenus: Menu.MenuOptions[] = [
		{
			path: "/home/index",
			title: "首页",
			icon: "HomeOutlined"
		},
		{
			path: "/assembly",
			title: "常用组件",
			icon: "AppstoreOutlined",
			children: [
				{
					path: "/assembly/guide",
					title: "引导页",
					icon: "QuestionCircleOutlined"
				},
				{
					path: "/assembly/svgIcon",
					title: "SVG 图标",
					icon: "PictureOutlined"
				},
				{
					path: "/assembly/selectIcon",
					title: "Icon 选择",
					icon: "SmileOutlined"
				},
				{
					path: "/assembly/batchImport",
					title: "批量导入数据",
					icon: "UploadOutlined"
				}
			]
		},
		{
			path: "/dashboard",
			title: "Dashboard",
			icon: "DashboardOutlined",
			children: [
				{
					path: "/dashboard/dataVisualize",
					title: "数据可视化",
					icon: "BarChartOutlined"
				},
				{
					path: "/dashboard/embedded",
					title: "内嵌页面",
					icon: "BorderOutlined"
				}
			]
		},
		{
			path: "/dataScreen",
			title: "数据大屏",
			icon: "DesktopOutlined"
		},
		{
			path: "/echarts",
			title: "Echarts",
			icon: "BarChartOutlined",
			children: [
				{
					path: "/echarts/waterChart",
					title: "水型图",
					icon: "BarChartOutlined"
				},
				{
					path: "/echarts/columnChart",
					title: "柱状图",
					icon: "BarChartOutlined"
				},
				{
					path: "/echarts/lineChart",
					title: "折线图",
					icon: "LineChartOutlined"
				},
				{
					path: "/echarts/pieChart",
					title: "饼图",
					icon: "PieChartOutlined"
				},
				{
					path: "/echarts/radarChart",
					title: "雷达图",
					icon: "RadarChartOutlined"
				},
				{
					path: "/echarts/nestedChart",
					title: "嵌套环形图",
					icon: "PieChartOutlined"
				}
			]
		},
		{
			path: "/form",
			title: "表单 Form",
			icon: "FormOutlined",
			children: [
				{
					path: "/form/basicForm",
					title: "基础 Form",
					icon: "FormOutlined"
				},
				{
					path: "/form/validateForm",
					title: "校验 Form",
					icon: "CheckCircleOutlined"
				},
				{
					path: "/form/dynamicForm",
					title: "动态 Form",
					icon: "FormOutlined"
				}
			]
		},
		{
			path: "/menu",
			title: "嵌套菜单",
			icon: "MenuOutlined",
			children: [
				{
					path: "/menu/menu1",
					title: "Menu1",
					icon: "MenuOutlined"
				},
				{
					path: "/menu/menu2",
					title: "Menu2",
					icon: "MenuOutlined",
					children: [
						{
							path: "/menu/menu2/menu21",
							title: "Menu2-1",
							icon: "MenuOutlined"
						},
						{
							path: "/menu/menu2/menu22",
							title: "Menu2-2",
							icon: "MenuOutlined",
							children: [
								{
									path: "/menu/menu2/menu22/menu221",
									title: "Menu2-2-1",
									icon: "MenuOutlined"
								},
								{
									path: "/menu/menu2/menu22/menu222",
									title: "Menu2-2-2",
									icon: "MenuOutlined"
								}
							]
						},
						{
							path: "/menu/menu2/menu23",
							title: "Menu2-3",
							icon: "MenuOutlined"
						}
					]
				},
				{
					path: "/menu/menu3",
					title: "Menu3",
					icon: "MenuOutlined"
				}
			]
		},
		{
			path: "/proTable",
			title: "超级表格",
			icon: "TableOutlined",
			children: [
				{
					path: "/proTable/useHooks",
					title: "使用 Hooks",
					icon: "ApiOutlined"
				},
				{
					path: "/proTable/useComponent",
					title: "使用 Component",
					icon: "CodeOutlined"
				}
			]
		},
		{
			path: "/link",
			title: "外部链接",
			icon: "LinkOutlined",
			children: [
				{
					path: "/link/github",
					title: "GitHub 仓库",
					icon: "GithubOutlined",
					isLink: "https://github.com/HalseySpike/Geeker-Admin"
				},
				{
					path: "/link/juejin",
					title: "掘金文档",
					icon: "ReadOutlined",
					isLink: "https://juejin.cn/post/7080820051420479525"
				},
				{
					path: "/link/myBlog",
					title: "个人博客",
					icon: "ReadOutlined",
					isLink: "https://blog.csdn.net/weixin_46970210?spm=1000.2115.3001.5343"
				},
				{
					path: "/link/gitee",
					title: "Gitee 仓库",
					icon: "CodeOutlined",
					isLink: "https://gitee.com/HalseySpike/Geeker-Admin"
				}
			]
		}
	];

	return Promise.resolve<{ code: number; msg: string; data: Menu.MenuOptions[] }>({
		code: 200,
		msg: "success",
		data: mockMenus
	});
};
